package Jcat.cduestcbbs.DaoImpl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import jcat.hbc.connectionpool.HBCConnectionPool;

import Jcat.cduestcbbs.Dao.RecordDao;
import Jcat.cduestcbbs.Po.RecordPo;

public class RecordDaoImpl implements RecordDao {

	public List<RecordPo> RecordQuery() throws SQLException {
		return null;
	}

	public boolean deleteRecord(RecordPo record) throws SQLException {
		return false;
	}

	public boolean insertRecord(RecordPo record) throws SQLException {
		Connection con = HBCConnectionPool.getInstance().getConnection();
		Statement st = con.createStatement();
		int i = st.executeUpdate("insert into record(record_content,"
				+ "record_persona_id,record_personb_id,record_time)values('"
				+ record.getRecordContent() + "','" + record.getRecordForMyId()
				+ "','" + record.getRecordForOtherId() + "','"
				+ record.getRecordTime() + "')");
		con.close();
		if (i > 0) {
			return true;
		} else {
			return false;
		}

	}

	public List<Object> getRecordListByUserId(int userId) throws SQLException {
		Connection con = HBCConnectionPool.getInstance().getConnection();
		List<Object> recordList = new ArrayList<Object>();
		Statement st = null;
		ResultSet rs = null;
		st = con.createStatement();
		rs = st
				.executeQuery("select record_content,record_time from record where record_persona_id='"
						+ userId + "' order by record_time limit 0,10");
		try {
			while (rs.next()) {

				recordList.add(rs.getString(2));
				recordList.add(rs.getString(1));

			}
		} finally {
			con.close();
		}
		return recordList;

	}
}
